<?php  
    require_once("./system/loginCheck.php");
    require_once("../congfig/config.php");

    $username=$_POST["username"];
    $pid=$_POST["pid"];
    echo $pid;
    $sql="select * from users where username='$username'";
    $result=$conn->query($sql);
    $row=$result->fetch_array();
    if ($row["uid"]!=null) {
    	$uid=$row["uid"];
    	$sql1="select * from puser where uid = $uid";
    	$result1=$conn->query($sql1);
        $row1=$result1->fetch_array();
        if($row1["id"]!=null){
        	$text="已经加入该项目，请勿重复添加！";
        	header("location:addProjectUser.php?text=$text&pid=$pid");
        }
        else{
        	  $sql2="insert into `puser`(`id`, `uid`, `pid`) values (null,$uid,$pid)";
        	  $result2=$conn->query($sql2);
        	  if ($result2==true) {
        	  	$text="成员添加成功，请继续添加！";
        	    header("location:addProjectUser.php?text=$text&pid=$pid");
        	  }
        	  else {
        	  	$text="添加失败！";
        	header("location:addProjectUser.php?text=$text&pid=$pid");
        	  }
            
        }
    }
    else{
    	$text="查不到此人信息，请确认名字输入正确!";
    	header("location:addProjectUser.php?text=$text&pid=$pid");
    }
    

?>